< previous page page_281 next page >

Page 281

Call ToggleButtons
End If
End Sub
analysis.gifThe lines in bold are the lines you need to add to the cmdSave_Click() event. First, you need to set the mboolError variable to a False value. When you call the Update method of the data control, the program will trigger events such as the WillChangeRecord event, in which youll set the mboolError variable to a True value if any of the fields are in error. Then, after the WillChangeRecord event has completed, control will pass back to the line after the Update method in the cmdSave_Click() event. You can check to see whether the mboolError variable is still a False value. If it is, you know you can go to the new record and toggle the buttons back to a valid value. Otherwise, you do nothing so that the user has to fix whatever fields are in error.

Data Control Error Handling
When dealing with an external database engine, you always have the potential for errors. As such, you need to have some good error handling in your program to account for these errors. The ADO data control has a built-in event thats called when theres an error related to the database or the table and/or fields contained in the data control.
Why Do Errors Happen?
Many things can go wrong when youre using a database. As such, you need to be prepared to handle these errors. Heres a list of things that can go wrong with a database:
Someone could have deleted the database.
The network is down and the database is on a shared network drive.
The database server is down.
The database is corrupted.
Someone has the database open for exclusive use.
Someone has the table open for exclusive use.

 
< previous page page_281 next page >

If you like this book, buy it!